/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;
using SMLib.Automata.MM;

namespace SMLib.Automata.Kripke
{
	public class NbitKripkeAsMealyWrapper: IBlackBox_MM
	{
		NbitKripke machine;
		NbitKripke.State currentState;

		public NbitKripkeAsMealyWrapper (NbitKripke machine)
		{
			this.machine = machine;
		}

		#region IBlackBox_MM implementation

		public void Reset ()
		{
			currentState = machine.InitialState;
		}

		public SMLib.Automata.Base.ISymbol Step (SMLib.Automata.Base.ISymbol input)
		{
			foreach (NbitKripke.Transition tr in currentState.Transitions)
				if (tr.Label.Equals (input)) {
					currentState = tr.Destination;
					return currentState.Output;
				}
			return null;
		}

		public SMLib.Automata.Base.Alphabet InputAlphabet {
			get {
				return machine.InputAlphabet;
			}
		}

		#endregion
	}
}

